import numpy as np

def padding_and_get_length(fed_wavs,ys,model_input_shape,model_output_shape,max_label_length):
    X=np.zeros((len(fed_wavs),)+model_input_shape,dtype=np.float64)
    y=np.zeros((len(fed_wavs),max_label_length),dtype=np.float32)
    input_length=[]
    label_length=[]
    for i in range(len(fed_wavs)):
        ws=fed_wavs[i].shape
        fed_wav=fed_wavs[i].reshape(ws[0],ws[1],1)
        pool_size=model_input_shape[0]//model_output_shape[0]
        inlen=min(ws[0]//pool_size+ws[0]%pool_size,model_output_shape[0])
        input_length.append(inlen)
        X[i,0:len(fed_wav)]=fed_wav
        y[i,0:len(ys[i])]=ys[i]
        label_length.append([len(ys[i])])
    label_length=np.matrix(label_length,dtype=np.int64)
    input_length=np.array([input_length],dtype=np.int64).T
    label=np.zeros((len(fed_wavs),1),dtype=np.float64)
    return [X,y,input_length,label_length],label,None

def padding(fed_wavs,ys,model_input_shape,max_label_length):
    X=np.zeros((len(fed_wavs),)+model_input_shape,dtype=np.float64)
    y=np.zeros((len(fed_wavs),max_label_length),dtype=np.int16)
    for i in range(len(fed_wavs)):
        ws=fed_wavs[i].shape
        fed_wav=fed_wavs[i].reshape(ws[0],ws[1],1)
        X[i,0:len(fed_wav)]=fed_wav
        y[i,0:len(ys[i])]=ys[i]
    return X,y,None

def padding_no_extra(fed_wavs,ys,model_input_shape,max_label_length): #没用
    X=np.zeros((len(fed_wavs),)+model_input_shape,dtype=np.float64)
    y=np.zeros((len(fed_wavs),max_label_length),dtype=np.int16)
    for i in range(len(fed_wavs)):
        ws=fed_wavs[i].shape
        if len(model_input_shape)==3:
            fed_wav=fed_wavs[i].reshape(ws[0],ws[1],1)
        X[i,0:len(fed_wav)]=fed_wav
        y[i,0:len(ys[i])]=ys[i]
    return X,y,None

def padding_without_y(fed_wavs,ys,model_input_shape):
    X=np.zeros((len(fed_wavs),)+model_input_shape,dtype=np.float64)
    for i in range(len(fed_wavs)):
        ws=fed_wavs[i].shape
        fed_wav=fed_wavs[i].reshape(ws[0],ws[1],1)
        X[i,0:len(fed_wav)]=fed_wav
    return X,ys,None

def infer_padding_without_y(fed_wavs,labels,ys,model_input_shape): # 没有被使用
    X=np.zeros((len(fed_wavs),)+model_input_shape,dtype=np.float64)
    for i in range(len(fed_wavs)):
        ws=fed_wavs[i].shape
        fed_wav=fed_wavs[i].reshape(ws[0],ws[1],1)
        X[i,0:len(fed_wav)]=fed_wav
    return X,labels,ys